package LinkList;

import org.junit.Test;

/**
 * @BelongsProject: SeniorArchitect-LeetCode
 * @BelongsPackage: LinkList
 * @Author: zhuangxiaoyan
 * @CreateTime: 2023-11-02  08:18
 * @Description: TODO
 * @Version: 1.0
 */
public class 删除排序链表的重复元素83 {


    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public ListNode deleteDuplicates(ListNode head) {
        ListNode dumpy = new ListNode(-1);
        dumpy.next = head;

        ListNode curr = dumpy;
        while (curr.next != null && curr.next.next != null) {
            if (curr.next.val == curr.next.next.val) {
                curr.next = curr.next.next;
            } else {
                curr = curr.next;
            }
        }
        return dumpy.next;
    }

    @Test
    public void tets() {
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(1);
        ListNode node3 = new ListNode(2);
        node1.next = node2;
        node2.next = node3;
        ListNode listNode = deleteDuplicates(node1);
        while (listNode!=null){
            System.out.print(listNode.val+"-》");
            listNode=listNode.next;
        }
    }
}
